# coding=utf-8
"""
做洗衣特殊的demo
"""
from datetime import datetime
import matplotlib.pyplot as plt
from matplotlib.dates import date2num
import matplotlib.dates as mdates


def plot_simple():
    fig = plt.figure(1)

    lines = plt.plot([1, 2, 3, 4])
    lines2 = plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
    plt.ylabel('y')
    plt.axis([0, 6, 0, 20]) # 设置坐标系

    print lines
    print lines2
    plt.show()

def fig_demo():
    plt.figure(1) # the first figure
    plt.subplot(211) # the first subplot in the first figure
    plt.plot([1, 2,     3])
    plt.subplot(212) # the second subplot in the first figure
    plt.plot([4, 5, 6])

    plt.figure(2)        # a second figure
    plt.plot([4, 5, 6])  # creates a subplot(111) by default
    plt.figure(1)        # figure 1 current; subplot(212) still current
    plt.subplot(211)     # make subplot(211) in figure1 current
    plt.title('Easy as 1, 2, 3')  # subplot 211 title
    plt.show()


def drawn():
    dates = ['2016-06-11', '2016-06-12','2016-06-13','2016-06-14','2016-06-15']
    dates2 = map(lambda x: date2num(datetime.strptime(x, "%Y-%m-%d")), dates)
    closes = [1, 2 ,3, 4, 5]
    fig = plt.figure()
    ax1 = fig.add_subplot(2, 1, 1)

    ax1.xaxis.set_major_locator(mdates.DayLocator(bymonthday=range(1, 32), interval=15))
    ax1.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m-%d"))
    for label in ax1.xaxis.get_ticklabels():
        label.set_rotation(45)
    ax1.plot(dates2, closes)

    ax2 = fig.add_subplot(2, 1, 2)
    ax2.plot(dates2, closes)
    plt.show()

if __name__ == "__main__":
    #plot_simple()
    #fig_demo()
    drawn()
